package net.oschina.allchat.message.processing.json;

import net.oschina.allchat.message.processing.ProcessingDescriptor;
import net.oschina.allchat.message.processing.json.parsers.core.IqParserFactory;
import net.oschina.allchat.message.processing.json.parsers.error.ErrorParserFactory;
import net.oschina.allchat.message.processing.json.parsers.error.StanzaErrorDetailsParserFactory;
import net.oschina.allchat.message.processing.json.parsers.error.StreamErrorDetailsParserFactory;
import net.oschina.allchat.message.processing.json.parsers.im.MessageParserFactory;
import net.oschina.allchat.message.processing.json.parsers.im.PresenceParserFactory;
import net.oschina.allchat.protocol.core.IError;
import net.oschina.allchat.protocol.core.ProtocolChain;
import net.oschina.allchat.protocol.core.stanza.Iq;
import net.oschina.allchat.protocol.core.stanza.error.StanzaError;
import net.oschina.allchat.protocol.core.stream.error.StreamError;
import net.oschina.allchat.protocol.im.stanza.Message;
import net.oschina.allchat.protocol.im.stanza.Presence;

public class StandardProcessingFactory extends ProcessingFactory {
	public StandardProcessingFactory() {
		super();
		registerStandardProtocols();
	}

	private void registerStandardProtocols() {
		register(ProtocolChain.first(Presence.PROTOCOL),
				new ProcessingDescriptor<Presence>(new PresenceParserFactory(), null));
		register(ProtocolChain.first(Message.PROTOCOL),
				new ProcessingDescriptor<Message>(new MessageParserFactory(), null));
		register(ProtocolChain.first(Iq.PROTOCOL),
				new ProcessingDescriptor<Iq>(new IqParserFactory(), null));
		register(ProtocolChain.first(StreamError.PROTOCOL), new ProcessingDescriptor<IError>(
				new ErrorParserFactory(IError.Type.STREAM), null));
		register(ProtocolChain.first(StanzaError.PROTOCOL), new ProcessingDescriptor<IError>(
				new ErrorParserFactory(IError.Type.STANZA), null));
		register(ProtocolChain.first(StreamError.PROTOCOL).next(StreamError.PROTOCOL_ERROR_DEFINED_CONDITION),
				new ProcessingDescriptor<Object>(new StreamErrorDetailsParserFactory(), null));
		register(ProtocolChain.first(StanzaError.PROTOCOL).next(StanzaError.PROTOCOL_ERROR_DEFINED_CONDITION),
				new ProcessingDescriptor<Object>(new StanzaErrorDetailsParserFactory(), null));
	}
}
